
		
	
*Panel B: Firm level data
eststo clear
use "$data\2_firm_regressions_individual_paper.dta", clear  
		

forval i = 2 / 4 {
label var empquality_`i' "Employment Quality"
label var sh_aminwage_`i' "Sh. Min. Wage"
label var sh_wrcon_`i' "Sh. Written Contract"
label var sh_sosec_`i' "Sh. Social Security"

}

global control i.broad_sector  i.ag_ano 

ren assignment ITT

estimates clear

global outcomes   sh_aminwage_2 sh_aminwage_3 sh_aminwage_4  sh_wrcon_2 sh_wrcon_3 sh_wrcon_4 sh_sosec_2 sh_sosec_3 sh_sosec_4   empquality_2 empquality_3 empquality_4 // 

	// Run regressions in loop 
	local c=1 
	foreach o of global outcomes {
		
		local d=`c'+1
		
		eststo ma`c': areg `o' ITT `o'_2021 $control i.wave mis_`o' i.wave  , vce(cl id) a(strata_all_coll)  
		qui summ `o' if ITT==0
		local mu : di %5.2f r(mean)
		estadd local mu `mu'

		
		local ++c 
	}

*Create Panel B ITT
esttab  ma* using "$results\01_tables\Table_S16_robust_weighting.tex", ///
   keep(ITT) ///
    b(%5.2f) se(%5.2f) ///
    star(* 0.10 ** 0.05 *** 0.01) ///
    stats(mu N, fmt(%9.2f %9.0f) labels("Mean" "\(N\)")) ///		
    nomtitles ///
    noline  ///
	nonotes ///
	nonumbers /// 
	prehead("\multicolumn{13}{l}{\textbf{Panel B:  Firm level data}}\\\hline\\[2pt]&\multicolumn{3}{c}{Min. Wage (0-1)}&\multicolumn{3}{c}{Written Contract (0-1)}&\multicolumn{3}{c}{Social Security (0-1)}&\multicolumn{3}{c}{Formality Index (0-1)}\\\cmidrule(lr){2-4}\cmidrule(lr){5-7}\cmidrule(lr){8-10}\cmidrule(lr){11-13}\\[2pt]") ///
		posthead("&\multicolumn{1}{c}{6 M.}&\multicolumn{1}{c}{18 M.}&\multicolumn{1}{c}{Pooled}&\multicolumn{1}{c}{6 M.}&\multicolumn{1}{c}{18 M.}&\multicolumn{1}{c}{Pooled}&\multicolumn{1}{c}{6 M.}&\multicolumn{1}{c}{18 M.}&\multicolumn{1}{c}{Pooled}&\multicolumn{1}{c}{6 M.}&\multicolumn{1}{c}{18 M.}&\multicolumn{1}{c}{Pooled}\\[2pt]\hline\\") ///
		prefoot("") ///
		postfoot("\\") ///
		replace
		
	global outcomes    aminwage wrcon  sosec  empquality_ind

	
* Panel A: Employee data weighted to firm level (ITT)
	eststo clear
	foreach x of numlist 1/3 {
		use "$data\4_individual_ano_reg_`x'.dta", clear
		ren assignment ITT
		local c=1 
		foreach o of global outcomes {
			local d=`c'+1
			eststo m`c'`x': areg `o' ITT `o'_2021 $controls_balance missing_`o'_2021 i.wave [pweight=w5] $se_indiv
			qui summ `o' if ITT==0
			local mu : di %5.2f r(mean)
			estadd local mu `mu'
			local ++c 
		}
	}

* Create Panel A 
esttab m1* m2* m3* m4* using "$results\01_tables\Table_S16_robust_weighting.tex", ///
   keep(ITT) ///
    b(%5.2f) se(%5.2f) ///
    star(* 0.10 ** 0.05 *** 0.01) ///
    stats(mu N, fmt(%9.2f %9.0f) labels("Mean" "\(N\)")) ///		
    nomtitles ///
    noline  ///
	nonotes ///
	nonumbers /// 
	prehead("\begin{tabular}{l*{12}{c}}\hline\hline\\[2pt]\multicolumn{13}{l}{\textbf{Panel A: Employee data weighted to firm level }}\\[2pt]\hline\\[2pt]&\multicolumn{3}{c}{Min. Wage (0/1)}&\multicolumn{3}{c}{Written Contract (0/1)}&\multicolumn{3}{c}{Social Security (0/1)}&\multicolumn{3}{c}{Formality Index (0-1)}\\\cmidrule(lr){2-4}\cmidrule(lr){5-7}\cmidrule(lr){8-10}\cmidrule(lr){11-13}\\[2pt]") ///
		posthead("&\multicolumn{1}{c}{6 M.}&\multicolumn{1}{c}{18 M.}&\multicolumn{1}{c}{Pooled}&\multicolumn{1}{c}{6 M.}&\multicolumn{1}{c}{18 M.}&\multicolumn{1}{c}{Pooled}&\multicolumn{1}{c}{6 M.}&\multicolumn{1}{c}{18 M.}&\multicolumn{1}{c}{Pooled}&\multicolumn{1}{c}{6 M.}&\multicolumn{1}{c}{18 M.}&\multicolumn{1}{c}{Pooled}\\[2pt]\hline\\") ///
		prefoot("") ///
		postfoot("\\") ///
		append
		
		
	